package com.guaju.yueshangLife.activity.setting;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.base.BaseActivity;
import com.guaju.yueshangLife.databinding.ActivitySetPayPassBinding;
import com.guaju.yueshangLife.textwatcher.SimpleTextWatcher;

public class SetPayPassActivity extends BaseActivity {


    private ActivitySetPayPassBinding binding;
    private StringBuilder sb;

    @Override
    protected void loadViewLayout() {

        binding = DataBindingUtil.setContentView(this, R.layout.activity_set_pay_pass);

    }

    @Override
    protected void bindViews() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        sb=new StringBuilder();

    }

    @Override
    protected void setListener() {
        binding.et1.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    binding.et2.requestFocus();
                    sb.append(s.toString());
                }
            }
        });
        binding.et2.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    binding.et3.requestFocus();
                    sb.append(s.toString());
                } else {
                    binding.et1.requestFocus();
                }
            }

        });
        binding.et3.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    binding.et4.requestFocus();
                    sb.append(s.toString());
                } else {
                    binding.et2.requestFocus();
                }
            }
        });
        binding.et4.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    binding.et5.requestFocus();
                    sb.append(s.toString());
                } else {
                    binding.et3.requestFocus();
                }
            }
        });
        binding.et5.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    binding.et6.requestFocus();
                    sb.append(s.toString());
                } else {
                    binding.et4.requestFocus();
                }
            }
        });
        binding.et6.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
//                    自动跳转到确认
                    sb.append(s.toString());
                    String firstPass = sb.toString();
                    Intent intent = new Intent(SetPayPassActivity.this, ConfirmPayPassActivity.class);
                    intent.putExtra("pay_pass",firstPass);
                    startActivity(intent);

                } else {
                    binding.et5.requestFocus();
                }
            }
        });
    }
}
